/**
 * (C) 2007 - 2009 Parleys.com NV.
 */
package com.parleys.core.service.impl;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.parleys.core.domain.Asset;
import com.parleys.core.domain.Presentation;
import com.parleys.core.exception.PresentationNotFoundException;
import com.parleys.core.service.PresentationService;

/**
 * 
 * @author berkay
 *
 */
@Service
public class PresentationServiceImpl implements PresentationService
{

    // BeJUG Channel
    Presentation presentation1 = new Presentation(1L, "SOA without SOAP", "Roy Fielding", "REST is a great alternative for WS-*");
    Presentation presentation2 = new Presentation(2L, "REST Patterns", "Stefan Tilkov", "The REST patterns explained and anti-patterns listed.");
    Presentation presentation3 = new Presentation(3L, "JAX-RS by Example", "Alex van Boxel", "The JAX-RS API explained by Alex van Boxel");

    // NLJUG Channel
    Presentation presentation4 = new Presentation(4L, "JavaSE 7", "Mark Reinhold", "The JavaSE 7 performance hints and tips");
    Presentation presentation5 = new Presentation(5L, "JSpring Keynote", "James Gosling", "JSpring keynote by Sun Microsystems");

    // Devoxx'08 Channel
    Presentation presentation6 = new Presentation(6L, "What is Scala", "Bill Venners", "Introduction to the Scala programming language");
    Presentation presentation7 = new Presentation(7L, "JRuby in Action", "Ruby Twins", "JRuby by the Ruby twins");
    Presentation presentation8 =
        new Presentation(8L, "What's new in Parleys.com", "Stephan Janssen", "This presentation shows what's new in Parleys.com");

    // Devoxx'09 Channel
    Presentation presentation9 = new Presentation(9L, "The Java Store", "James Gosling", "The Java Store demonstrated");
    Presentation presentation10 = new Presentation(10L, "JavaPosse.com", "The Posse", "The JavaPosse does a live recording at Devoxx");
    Presentation presentation11 = new Presentation(11L, "ScalaTest", "Bill Venners", "How to test Scala programs using ScalaTest");
    Presentation presentation12 = new Presentation(12L, "Closures", "Mark Reinhold", "How will closures look like in Java SE 7?");

    // Test Channel
    Presentation presentation13 = new Presentation(13L, "Test", "Unknown", "This is a test presentation");

    // Internal Channel
    Presentation presentation14 = new Presentation(14L, "Profit and Loss", "The CFO", "The profit and loss presentation of comapny x");
    Presentation presentation15 = new Presentation(15L, "Our Competitors", "The CEO", "The competitors overview of company x");

    @PostConstruct
    public void populatePresentations()
    {
        presentation1.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation1.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation2.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation2.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation3.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation3.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation4.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation4.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation5.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation5.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation6.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation6.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation7.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation7.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation8.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation8.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation9.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation9.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation10.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation10.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation11.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation11.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation12.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation12.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation13.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation13.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation14.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation14.addAsset(new Asset(2L, "slide2.swf", 500L));

        presentation15.addAsset(new Asset(1L, "slide1.swf", 0L));
        presentation15.addAsset(new Asset(2L, "slide2.swf", 500L));
    }

    @Override
    public Presentation getPresentation(Long id)
    {
        for(Presentation presentation : getPresentations())
        {
            if(presentation.getId().equals(id))
            {
                return presentation;
            }
        }
        throw new PresentationNotFoundException(id);
    }

    @Override
    public Collection<Presentation> getPresentations()
    {
        Collection<Presentation> presentations = new ArrayList<Presentation>();
        presentations.add(presentation1);
        presentations.add(presentation2);
        presentations.add(presentation3);
        presentations.add(presentation4);
        presentations.add(presentation5);
        presentations.add(presentation6);
        presentations.add(presentation7);
        presentations.add(presentation8);
        presentations.add(presentation9);
        presentations.add(presentation10);
        presentations.add(presentation11);
        presentations.add(presentation12);
        presentations.add(presentation13);
        presentations.add(presentation14);
        presentations.add(presentation15);
        return presentations;
    }

}
